﻿namespace Moe.ECamel.Common.Entities
{
	using System;
	using System.ComponentModel;

	public partial class Library : IEditableObject
	{
		public ECamelError Validate()
		{
			// Verify mandatory fields:
			string emptyFields = null;
			if (String.IsNullOrEmpty(_LibraryName))
				emptyFields += "שם ספריה" + Environment.NewLine;
			if (emptyFields != null)
				return new ECamelError(MessageIds.LibraryInvalidMissingFields, emptyFields);

			return null;
		}

		private string _parentLibraryName;
		public string ParentLibraryName
		{
			get { return _parentLibraryName; }
			set { _parentLibraryName = value; }
		}

		#region IEditableObject Members

		private Library _originalEntity = null;

		public void BeginEdit()
		{
			if (this._originalEntity == null)
			{
				// Initialize original library 
				this._originalEntity = new Library();
				// Copy editable properties values:
				this._originalEntity._LibraryName = this._LibraryName;
				this._originalEntity._Address = this._Address;
				this._originalEntity._Telephone = this._Telephone;
				this._originalEntity._Fax = this._Fax;
				this._originalEntity._OpeningHours = this._OpeningHours;
				this._originalEntity._Active = this._Active;
			}
		}

		public void CancelEdit()
		{
			if (this._originalEntity != null)
			{
				// Restore properties:
				this._LibraryName = this._originalEntity._LibraryName;
				this._Address = this._originalEntity._Address;
				this._Telephone = this._originalEntity._Telephone;
				this._Fax = this._originalEntity._Fax;
				this._OpeningHours = this._originalEntity._OpeningHours;
				this._Active = this._originalEntity._Active;
				// Reset original values:
				this._originalEntity = null;
			}
		}

		public void EndEdit()
		{
			// Reset original values:
			this._originalEntity = null;
		}

		#endregion
	}
}